<%-- 
    Document   : cargar_rdf
    Created on : 6/10/2014, 11:56:19 PM
    Author     : Cristian, Edwin
--%>

<%@page import="com.hp.hpl.jena.util.FileManager"%>
<%@page import="java.io.InputStream"%>
<%@page import="Class.*" %>
<%@page import="javazoom.upload.*,java.util.*" %>

<jsp:useBean id="upBean" scope="page" class="javazoom.upload.UploadBean" >
</jsp:useBean>

            <%-- Load File in folder Temp --%>
            <%
                UploadFile file=null, file2=null;
                String jspPath = session.getServletContext().getRealPath("/");
                String fullPath = jspPath + "\\data\\";
                String fullPathFile = "";
                String fullPathFile2 = "";
                upBean.setFolderstore(jspPath + "\\data");
                if (MultipartFormDataRequest.isMultipartFormData(request)) {
                    // Uses MultipartFormDataRequest to parse the HTTP request.
                    MultipartFormDataRequest mrequest = new MultipartFormDataRequest(request);

                    Hashtable files = mrequest.getFiles();
                    if ((files != null) && (!files.isEmpty())) {
                        file = (UploadFile) files.get("url");
                        file2 = (UploadFile) files.get("url2");
                        if (file != null) {
                            // Uses the bean now to store specified by jsp:setProperty at the top.
                            upBean.store(mrequest, "url");
                            fullPathFile = fullPath + file.getFileName();
                        } else {

                            out.print("Error loading file.");

                        }

                        if (file2 != null) {
                            // Uses the bean now to store specified by jsp:setProperty at the top.
                            upBean.store(mrequest, "url2");
                            fullPathFile2 = fullPath + file2.getFileName();
                        } else {

                            out.print("Error loading file.");

                        }
                    } else {

                        out.print("Error loading file.");
                    }
                    if (mrequest.getParameter("urlUnion") != null && mrequest.getParameter("urlUnion").equals("Union")) {
                        Union u = new Union();
                        u.executeUnion(fullPathFile, fullPathFile2, fullPath);
                    }
                    else if (mrequest.getParameter("urlInterseccion") != null && mrequest.getParameter("urlInterseccion").equals("Interseccion")) {
                        Intersection i = new Intersection();
                        i.executeIntersection(fullPathFile, fullPathFile2, fullPath);
                    }
                    
                    response.setStatus(response.SC_MOVED_TEMPORARILY);
                    response.setHeader("Location", "../index.jsp");
                } 
            %>